import lawTopBar from "@/components/lawTopBar/index";
import { getTaxList } from "@/static/js/law.js";
export default {
  components: {
    lawTopBar,
  },
  data() {
    return {
      title: "税收法规库",
      backgroundUrl: require("@/static/img/law/topBar_bg_01.png"),
      sortList: [
        {
          id: 1,
          nid: 1,
          name: "热点法规",
        },
        {
          id: 2,
          nid: 2,
          name: "中央法规",
        },
        {
          id: 3,
          nid: 3,
          name: "地方法规",
        },
        {
          id: 27,
          name: "海关综合文件",
        },
        {
          id: 20,
          name: "国际跨境税收",
        },
        {
          id: 28,
          name: "外汇文件",
        },
        {
          id: 32,
          name: " 12366热点问答",
        },
        {
          nid: 4,
          name: "法规法条",
        },
      ], //分类
      chooseTagId: 1,
      form: {
        keyword: "", //	否	string	搜索字段
        city_code: "", //	否	string	城市编码
        policy_cate_id: "",
        is_hot: 1,
        is_fatiao: "", //是否法规发条 1：是 0：否
        title_keyword: "", //标题关键字
        cons_keyword: "", //内容关键字
      },
      query: {
        type: 2, //	是	string	类型:1=优惠政策,2=税收法规
        page: 1,
        limit: 10,
        maxpage: 1,
      },
      isLoading: false,
      loadMoreStatue: "more",
      count: 0,
      lawList: [],
      isRefreshing: false,
      loadMoreStatus: "more",
    };
  },
  methods: {
    //选择分类
    chooseTag(e) {
      this.chooseTagId = e.id;
      this.form.is_fatiao = "";
      this.form.policy_cate_id = "";
      this.form.is_hot = "";
      this.form.city_code = "";
      this.query.page = 1;
      if (e.nid == 1) {
        this.form.is_hot = 1;
      } else if (e.nid == 2) {
        this.form.city_code = 1;
      } else if (e.nid == 3) {
        this.form.city_code = -1;
      } else if (e.nid == 4) {
        this.form.is_fatiao = 1;
      } else {
        this.form.policy_cate_id = e.id;
      }
      this.lawList = [];
      this.getList();
    },

    //请求列表数据
    getList() {
      uni.showLoading({
        title: "加载中",
      });
      if (this.query.page == 1) {
        this.dataList = [];
        this.isLoading = true;
      } else {
        this.loadMoreStatue = "loading";
      }
      getTaxList({ ...this.form, ...this.query }).then((res) => {
        uni.hideLoading();
        if (res.code == 1) {
          if (res.data.length > 0) {
            this.count = res.data[0].all_count;
          } else {
            this.count = 0;
          }
          if (this.query.page == 1) {
            this.lawList = [];
          }
          var newList = res.data;
          if (newList.length >= this.query.limit) {
            this.loadMoreStatus = "more";
          } else {
            this.loadMoreStatus = "noMore";
          }
          this.lawList = [...this.lawList, ...newList];
          this.isRefreshing = false;
        } else {
          this.$tools.showToast(res.msg);
          this.loadMoreStatus = "noMore";
        }
      });
    },

    //下拉刷新
    reload() {
      this.query.page = 1;
      this.lawList = [];
      this.isRefreshing = true;
      this.getList();
    },

    //加载更多
    loadMore() {
      if (this.loadMoreStatus == "more") {
        this.query.page++;
        console.log(this.query.page);
        this.getList();
      } else {
        this.$tools.msg("没有更多了");
      }
    },

    //去詳情
    toInfo(id) {
      uni.navigateTo({
        url: "../det/index?id=" + id,
      });
    },

    //去搜索
    goSearch() {
      uni.navigateTo({
        url: "../search/index",
      });
    },
  },
  onReady() {},
  onShow() {},
  onLoad(e) {
    this.getList();
  },
};